// var itemList = require('../../common/itemList/itemList.js');
var goods_table = require('../../template/goodsTable/goods_table.js')
//index.js
var app = getApp();
Page({
  data: {
    swiperHeight: 0,
    moduleArray: [],
    bannerList: ["https://m15.360buyimg.com/mobilecms/s1062x420_jfs/t1/117562/4/33901/149662/63bff17cFd91e5795/2a51b0fdfc510199.jpg!cr_1053x420_4_0!q70.jpg","https://m15.360buyimg.com/mobilecms/s1062x420_jfs/t1/66479/13/21399/65518/62e271dfE4dc4181f/2d7c014f2d37b45b.jpg!cr_1053x420_4_0!q70.jpg"],
    active: ['//m.360buyimg.com/babel/jfs/t1/81367/35/24625/43458/63c1083dF0d139955/c6037b6edc53f4da.png.avif','//m.360buyimg.com/babel/jfs/t1/81367/35/24625/43458/63c1083dF0d139955/c6037b6edc53f4da.png.avif','//m.360buyimg.com/babel/jfs/t1/169215/17/33858/14904/63bccd2dF3bf9c641/c1c807c78fdf44a1.png.avif','//m.360buyimg.com/babel/jfs/t1/98507/6/29060/87745/63b40754Ff578e626/b33d4f697ea59583.png.avif','//m.360buyimg.com/babel/jfs/t1/174565/15/30456/16305/63b40012F0d108b3a/969fc2641c47544a.png.avif','//m.360buyimg.com/babel/jfs/t1/71726/21/18016/15616/63c11d80F7cd2b54e/f4345fb6c76d7293.png.avif'],
    goods: [],
    hidden: ''
  },
  // 滚动时颜色改变
  scrollChangeBgColor: function(e) {
    console.log(e);
  },
  scrollBottom: function(e) {
    console.log(e);
  },

  // 增加操作
  actionAdd: function(e) {
    itemList.add(e);
  },
  SaoMa: function(e) {
    // 只允许从相机扫码
    wx.scanCode({
      onlyFromCamera: true,
      success(res) {
        console.log(res)
      }
    })
  },
  //根据轮播图高度，动态设置Swpier高度
  SetSwiperHeight: function(e) {
    var imgwidth = e.detail.width;
    var imgheight = e.detail.height;
    //宽高比  
    var ratio = imgwidth / imgheight;
    console.log(imgwidth, imgheight);
    //计算的高度值  
    var viewHeight = 750 / ratio;
    // var imgheight = viewHeight;
    // var imgheights = this.data.imgheights;

    this.setData({
      swiperHeight: viewHeight
    })
  },
  //关闭首页弹出层
  CloseIndexAd: function() {
    wx.showTabBar({});
    this.setData({
      hidden: 'hidden'
    });
    // wx.getLocation({
    //   type: 'wgs84',
    //   success: function(res) {
    //     const latitude = res.latitude;
    //     const longitude = res.longitude;
    //     const speed = res.speed;
    //     const accuracy = res.accuracy;
    //     console.log(res);

    //   },
    // })
  },
  GoList: function() {
    wx.navigateTo({
      url: '../goods/list/list'
    })
  },
  GetGoodsData:function(e)
  {
      var g=[];
      for (let i = 0; i < 10; i++) {
        g.push('');
      }
      var goods = goods_table.getGoods();
      this.setData({goods:goods});
  },
  GoGoodsDetail: function(e) {
    wx.navigateTo({
      url: '../goods/detail/detail?id=' + e.currentTarget.dataset.id
    })
  },
  /**
   * 生命周期函数--监听页dr面加载
   */
  onLoad: function(options) {
    wx.hideTabBar({});
    this.moduleArray=[{img:'',title:'2222'}];
    var that = this;


    const webUrl="https://m15.360buyimg.com/mobilecms/jfs/t1/";
    var module=[
      {img:'187640/12/30456/5256/639c2315Ebc95c142/350a8f0c766f5460.png',title:'京东超市'},
      {img:'178015/31/13828/6862/60ec0c04Ee2fd63ac/ccf74d805a059a44.png',title:'数码电器'},
      {img:'54043/33/19389/4660/62b049dbE3b9aef75/2fcd31afd5d702e4.png',title:'日常百货'},
      {img:'177902/16/13776/5658/60ec0e71E801087f2/a0d5a68bf1461e6d.png',title:'生活生鲜'},
      {img:'196472/7/12807/7127/60ec0ea3Efe11835b/37c65625d94cae75.png',title:'配送到家'},
      {img:'185733/21/13527/6648/60ec0f31E0fea3e0a/d86d463521140bb6.png',title:'缴费充值'},
      {img:'34248/39/16616/4689/62bbbdccE9f11132e/d51caf15f2f412b2.png',title:'附件好店'},
      {img:'186080/16/13681/8175/60ec0fcdE032af6cf/c5acd2f8454c40e1.png',title:'领优惠券'},
      {img:'37709/6/15279/6118/60ec1046E4b5592c6/a7d6b66354efb141.png',title:'VIP会员'},
      {img:'191060/24/12861/6818/60ec11f2E67cf5ee6/c264378678b3cd96.png',title:'国际商城'},
    ];
    for (let i = 0; i < module.length; i++) {
      module[i].img=webUrl+module[i].img;
    }
    //console.log(module);
    that.setData({
      moduleArray: module
    });

    //GetGoodsData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
   this.GetGoodsData();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})